<?php
use \yii\helpers\Url;
\backend\assets\PickerAsset::register($this);
use common\models\Percentage\Percentage;
?>
<?php $this->beginBlock('content') ?>
<div class="row">
    <div class="col-sm-12">
        <div class="white-box">
            <h3 class="box-title"></h3>
            <div class="row m-b-15">
                <div class="col-sm-10">
                    <form action="">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="input-group">
                                    <div class="input-daterange input-group" id="date-range">
                                        <input type="text" class="form-control"  rel-type="date" name="date_view" value="<?=Yii::$app->request->get('date_view')?>" placeholder="日期">
                                    </div>
                                    &nbsp;&nbsp;
                                    <?php if (@$percentage["status"] == Percentage::STATUS_NO) : ?>
                                    <div class="input-daterange input-group">
                                        <input type="text" class="form-control"   name="upper_terminal_view" value="<?=Yii::$app->request->get('upper_terminal_view')?>" placeholder="上游终端数">
                                    </div>
                                    <?php endif ?>

                                    &nbsp;  <select class="selectpicker" name="plug_id_view">
                                        <option value="">业务插件</option>
                                        <?php foreach ($plugs as $v):?>
                                            <option value="<?=$v["id"]?>" <?php if (Yii::$app->request->get("plug_id_view") == $v["id"]) : ?>selected<?php endif ?>><?=$v["name"]?></option>
                                        <?php endforeach;?>
                                    </select>
                                    <span class="input-group-btn">
                                        <button class="btn btn-info" type="submit">
                                            预览
                                        </button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="col-sm-2">
                    <form action="<?=Url::to(["sure"])?>" rel-action="form" method="post">
                        <input type="hidden" class="form-control"  name="date" value="<?=Yii::$app->request->get('date_view')?>" placeholder="日期">
                        <input type="hidden" class="form-control"   name="plug_id" value="<?=Yii::$app->request->get('plug_id_view')?>" placeholder="类型">
                        <input type="hidden" class="form-control"   name="upper_terminal" value="<?=Yii::$app->request->get('upper_terminal_view')?>" placeholder="类型">
                        <input type="hidden" name="code">
                        <input type="hidden" name="md5">
                        <?php if (@$percentage["status"] == Percentage::STATUS_NO) : ?>
                            <button  style="border:1px solid #fb9678" type="button" class="fcbtn btn btn-danger btn-outline btn-1e" id="sure" >
                                确认分成
                            </button>
                        <?php endif ?>
                    </form>
                </div>
                <span style="margin-left: 8px;margin-top: 15px;margin-bottom: 15px">
                        <?php if (isset($error)) : ?>
                            错误信息：<span class="wsc2" style="color: red"><?=$error?></span>
                            <br><br>
                        <?php endif ?>
                        业务插件：<span class="wsc2" style="color: #0b67cd"><?=@$percentage["plug"]["name"]?></span>，
                        分成状态：<span class="wsc-1" style="color:red"><?=Percentage::getStatusMap(@$percentage["status"])?></span>
                        <br><br>
                        上报分成终端数：<span class="wsc2" style="color: #0b67cd"><?=intval(@$percentage["real_num"])?></span>，
                        后期填写上游终端数：<span class="wsc2" style="color: #0b67cd"><?=intval(@$percentage["upper_num"])?></span>，
                        总上报终端：<span class="wsc2" style="color: #0b67cd"><?=@$totalRet?></span>，
                </span>
            </div>
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>发生时间</th>
                        <th>代理商</th>
                        <th>区域经理</th>
                        <th>软件上报终端数</th>
                        <th>上游终端数</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ((array)@$ret as $item):?>
                        <tr>
                            <td><?=isset($item["created_time"]) ? $item["created_time"] : \common\components\DataHelper::date()?></td>
                            <td><?=$item["agent_name"] ? $item["agent_name"] : "【agent id：".$item["agent_id"]."】"?></td>
                            <td><?=$item["manager_name"] ? $item["manager_name"] : $item["manager_id"]?></td>
                            <td><?=$item["real_num"]?></td>
                            <td><?=$item["upper_num"]?></td>
                        </tr>
                    <?php endforeach ?>
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="12" class="footable-visible">
                            <div class="text-right">
                                <?php if (isset($page) && $page) : ?>
                                <?=\common\components\DataHelper::getLinkPager($page)?>
                                <?php endif ?>
                            </div>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>
<?php $this->endBlock(); ?>
<?php $this->beginBlock("script")?>
<script>
    $("#sure").click(function(){
        $("[rel-action=form]").submit();
        /*$("[name=date]").val($("[name=date_view]").val());
        $("[name=amount]").val($("[name=amount_view]").val());
        $("[name=ad_type]").val($("[name=ad_type_view]").find("option:selected").val());
        if ( $("[name=md5]").val() ) {
            alertInput("短信验证码", "", "", function(inputValue, index){
                $("[name=code]").val(inputValue);
                $("[rel-action=form]").submit();
                top.swal.close(index);
            });
        } else {
            $.post("/sms/send", {type:2}, function(response){
                if ( response.status == 0 ) {
                    alertError(response.message);
                    return false;
                }
                alertInput("短信验证码", "", "", function(inputValue, index){
                    $("[name=code]").val(inputValue);
                    $("[rel-action=form]").submit();
                    top.swal.close(index);
                });
                $("[name=md5]").val(response.data["md5"]);
            }, "json");
        }*/
        return false;
    })
</script>
<?php $this->endBlock(); ?>
